package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IProductService;
import com.mall.shopping.dto.*;
import com.mall.user.annotation.Anoymous;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author lichao
 * @createdate 2021-01-25 10:39
 */

@RestController
@RequestMapping("/shopping")

public class ShoppingController {

    @Reference(timeout = 300000,check = false,retries = 0)
    IProductService iProductService;

    /**
     * 商品详情
     * @param id
     * @return
     */
    @RequestMapping("/product/{id}")
    @Anoymous
    public ResponseData product(@PathVariable("id")Long id){

        ProductDetailRequest productDetailRequest = new ProductDetailRequest();

        productDetailRequest.setId(id);

        productDetailRequest.requestCheck();

        ProductDetailResponse productDetailResponse = iProductService.getProductDetail(productDetailRequest);

        return new ResponseUtil<ProductDetailDto>().setData(productDetailResponse.getProductDetailDto());
    }

    /**
     * 所有商品
     * @param allProductRequest
     * @return
     */
    @RequestMapping("/goods")
    @Anoymous
    public ResponseData goods(AllProductRequest allProductRequest){

        allProductRequest.requestCheck();
        AllProductResponse allProduct = iProductService.getAllProduct(allProductRequest);
        Map<String, Object> map = new HashMap<>();

        map.put("data",allProduct.getProductDtoList());
        map.put("total",allProduct.getTotal());
        return new ResponseUtil<Map>().setData(map);
    }

    /**
     * 推荐商品
     * @param
     * @return
     */
    @RequestMapping("/recommend")
    @Anoymous
    public ResponseData recommend(){

        RecommendResponse recommendGoods = iProductService.getRecommendGoods();

        return new ResponseUtil<Set>().setData(recommendGoods.getPanelDtos());
    }


}
